<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>忘记密码</title>
		<meta name="Description" content="" />
		<meta name="Keywords" content="" />
		<meta name="format-detection" content="telephone=no, email=no" />
		<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
		<!-- 忽略页面中的数字识别为电话，忽略email识别 -->
		<meta name="applicable-device" content="mobile" />
		<meta name="apple-mobile-web-app-title" content="" />
		<!-- 添加到主屏后的标题（iOS 6 新增） -->
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<!-- 是否启用 WebApp 全屏模式 -->
		<meta name="HandheldFriendly" content="true" />
		<!-- 针对手持设备优化，主要是针对一些老的不识别viewport的浏览器，比如黑莓 -->
		<meta name="author" content="Jack" />
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="../../js/flexible.js" type="text/javascript" charset="utf-8"></script>		
		<link rel="stylesheet" type="text/css" href="../../style/jquery_css/weui.css"/>
		<link rel="stylesheet" type="text/css" href="../../style/jquery_css/jquery-weui.css"/>
		<link rel="stylesheet" type="text/css" href="../../style/main.css" />
		<link rel="stylesheet" type="text/css" href="../../style/icon.css"/>			
	</head>
	<body>
		<div class="main-box">
			<div class="login-cen">
				<div class="login-main-font">忘记密码</div>
				<div>
					<div>
						<input type="text" class="login-phone-input" placeholder="请输入手机号" id="phone-num"/>
					</div>
					<div class="top-pwd">
						<input type="text" class="login-phone-input code-input" placeholder="请输入验证码" id="verify_code"/>
						<span class="code-span">
							<button class="code-get" id="get-code-my" onclick="get_email_code()">获取验证码</button>
						</span>
						
					</div>
					<div class="input-dsc">
						<input type="password" class="login-phone-input" placeholder="请输入新密码" id="find-pwd1"/>
					</div>
					<div class="login-btn-top">
						<button class="UDC-btn UDC-btn-bg" onclick="forget_pwd()">完成</button>
					</div>
					<div class="return-login">
						<a href="login.html" class="">返回登录</a>
					</div>
					
				</div>
			</div>
			
		</div>
					
	</body>
	<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/weiUI/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/api/api_url.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../js/api/port_url.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		function forget_pwd(){
			var reg = /^1(3|4|5|6|7|8|9)\d{9}$/;
			if($.trim($('#phone-num').val()) == ''){
        		$.toast("请输入手机号!", "text");
                return false;
            }
			if(!reg.test($.trim($('#phone-num').val()))) {
				$.toast("请输入正确的手机号!", "text");
                return false;
            }
			if($.trim($('#verify_code').val()) == ''){
        		$.toast("请输入验证码!", "text");
                return false;
            }
			if($.trim($('#find-pwd1').val()) == ''){
            	$.toast("请填写新密码!", "text");
                return false;
            }
            if($.trim($('#find-pwd1').val()).length<6){
            	$.toast("新密码不能小于6位数!", "text");
                return false;
            }
            
            
            
            $.ajax({
				url: config_URL.api+URL.getPassword, //请求的url地址
				dataType: "json", //返回格式为json
				data:{
					access_token:'26cd1cce6e231c7dd92b149d04008037',
					username:$('#phone-num').val(),
					code:$('#verify_code').val(),
					password:$('#find-pwd1').val()
				},
				type: "POST", //请求方式
				success: function(res) {
					if(res.code==0){
						$.toast("密码已重置!", "text");
						setTimeout(function() {
							window.location.href = 'login.html'
						}, 3000)
						
					}else{
						$.toast(res.msg, "text");
					}
					
					
				},
				error: function(rul) {
					console.log('网络出错')
				}
			});
		}
		
		
		//获取邮箱验证码
		function get_email_code(){
			var reg = /^1(3|4|5|6|7|8|9)\d{9}$/;
			if($.trim($('#phone-num').val()) == ''){
        		$.toast("请输入手机号!", "text");
                return false;
            }
			if(!reg.test($.trim($('#phone-num').val()))) {
				$.toast("请输入正确的手机号码!", "text");
                return false;
            }
			$.showLoading(' ');
			$.ajax({
				url: config_URL.api+URL.send, //请求的url地址
				dataType: "json", //返回格式为json
				data:{
					access_token:'a7fa17645ff7f03cd90b292cf96fa535',
					phone:$('#phone-num').val(),
					type:'2'
				},
				type: "POST", //请求方式
				success: function(res) {
					console.log(res)
					if(res.code==0){
						$.hideLoading();
						$.toast("验证码已发送!", "text");
						$("#get-code-my").addClass("on");
						  var time = 60;
						  $("#get-code-my").attr("disabled", true);
						  var timer = setInterval(function() {
						   if (time == 0) {
						    clearInterval(timer);
						    $("#get-code-my").attr("disabled", false);
						    $("#get-code-my").text("获取验证码");
						    $("#get-code-my").removeClass("on");
						   } else {
						    $('#get-code-my').text(time + "s重新获取");
						    time--;
						   }
						  }, 1000);
					}else{
						$.toast(res.msg, "text");
					}
					
					
				},
				error: function(rul) {
					console.log('网络出错')
				}
			});
			
		}
	</script>
</html>
